from flask import request, jsonify

from com.linkstec.service.user_service import UserService


class RouteTestController:
    def __init__(self, app):
        self.app = app
        # 在这里注册路由
        self.register_routes()
        self.service = UserService()

    def register_routes(self):
        @self.app.route('/test/users', methods=['GET'])
        def list_users1():
            users = self.service.list_users()
            return jsonify([u.__dict__ for u in users])

        @self.app.route('/test/users/<int:user_id>', methods=['GET'])
        def get_user1(user_id: int):
            user = self.service.get_user(user_id)
            return jsonify(user.__dict__) if user else ('Not found', 404)
